import copy
from django.template import Library

from django.conf import settings

register = Library()


@register.inclusion_tag("tag/nb_menu.html")
def nb_menu(request):
    # 读取当前用户角色信息
    # print(request.nb_user.role)

    # 2 菜单信息
    user_menu_list = copy.deepcopy(settings.NB_MENU[request.nb_user.role])

    # print('request.nb_user.menu_name---------------------------------', request.nb_user.menu_name)
    for item in user_menu_list:
        # item['class'] = 'hide'

        for child in item["children"]:
            # if child['url'] == request.path_info: v1版本
            if child['name'] == request.nb_user.menu_name:  # v2版本 'level_list'
                child['class'] = 'active'
                # item['class'] = ''
    # print('>>>>>>>>>>>>', request.path)
    # print('>>>>>>>>>>>>', '/%s/' % request.path.strip('/').split('/')[0])
    # print('user_menu_list=============================================', user_menu_list)
    return {'menu_list': user_menu_list}
